/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSArticulo;


import Entidades.Revision.Articulo;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Nory (L)
 */
@Stateless
@LocalBean
public class ArticuloDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    EntityManager em;
    public void crear(Articulo a) {
        em.persist(a);
    }

    public void actualizar(Articulo a) {
        em.merge(a);
    }

    public void borrar(Integer id) {
        Articulo art = em.find(Articulo.class, id);
        em.remove(art);
    }

    public void guardar(Articulo a) {
        if (a.getIdArticulo() == null) {
            crear(a);
        } else {
            actualizar(a);
        }
    }

    public List<Articulo> BuscarTodos() {
        return em.createNamedQuery("Articulo.findAll", Articulo.class).getResultList();
    }

    public List<Articulo> BuscarArticulo(String cadena) {
        return em.createNamedQuery("Articulo.findByTitulo", Articulo.class)
                .setParameter("Titulo", cadena).getResultList();
    }
}
